﻿<UserControl x:Class="Adalbertus.BudgetPlanner.Views.ExternalSources.SavingsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:cal="http://www.caliburnproject.org"
             xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended" 
>
    <ItemsControl ItemsSource="{Binding Savings}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <GroupBox Margin="4">
                    <GroupBox.Header>
                        <WrapPanel>
                            <Label>Nazwa</Label>
                            <TextBox Text="{Binding Name}" Width="150" />
                            <Label>Łącznie</Label>
                            <Label Content="{Binding TotalValue}" />
                            <Button Content="X" ToolTip="Usuń oszczędności" cal:Message.Attach="[Event Click] = [Action RemoveSaving($dataContext)]"/>
                            <Button Content="+" ToolTip="Uwaga - Oszczędności powinny być dodawane z poziomu budżetu!" cal:Message.Attach="[Event Click] = [Action AddSavingEntry($dataContext)]"/>
                        </WrapPanel>
                    </GroupBox.Header>
                    <DataGrid ItemsSource="{Binding Entries}" CanUserAddRows="False" CanUserDeleteRows="False" 
                                          AutoGenerateColumns="False" MaxHeight="100">
                        <DataGrid.Columns>
                            <DataGridTemplateColumn Header="Data">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <extToolkit:DateTimePicker Value="{Binding Date}"
                                                                   Format="LongDate"                                                                   
                                                                   ShowButtonSpinner="False"  />
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                            <DataGridTemplateColumn Header="Kwota">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <extToolkit:DecimalUpDown Value="{Binding Value}" DefaultValue="0"
                                                                  SelectAllOnGotFocus="True"
                                                                  ShowButtonSpinner="False"/>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                            <DataGridTextColumn Header="Budżet" Binding="{Binding Budget}" IsReadOnly="True" />
                            <DataGridTextColumn Header="Uwagi" Binding="{Binding Description}" />
                            <DataGridTemplateColumn>
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button Content="X" cal:Message.Attach="[Event Click] = [Action RemoveSavingEntry($dataContext)]"/>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                </GroupBox>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</UserControl>
